# -*-coding: Utf-8 -*-
# @File : common .py
# author: Chimengmeng
# blog_url : https://www.cnblogs.com/dream-ze/
# Time：2023/6/10
import random
from core import src
import time


def get_random_code(n):
    # 随机生成数字
    number = str(random.randint(0, 9))
    # 随机生成大写字母
    code_Big = chr(random.randint(65, 90))
    # 随机生成小写字母
    code_Small = chr(random.randint(97, 122))
    # 随机字符串待选项
    choice = ['*', '/', '_', '\\', '&']
    # 随机字符串
    spical_code = random.choice(choice)
    # 初始化随机字符串
    random_code = ''
    # 循环拼接字符串
    for i in range(n):
        temp = random.choice([number, code_Big, code_Small])
        random_code += temp

    return random_code


# 全局开始时间
start_time = time.time()


def login_check(func_name):
    def inner(*args, **kwargs):
        if src.login_user:
            res = func_name(*args, **kwargs)
            print(f'当前功能已运行时间{time.time() - start_time}s')
            return res
        else:
            print('当前用户未登陆,开始登陆!')
            src.login()

    return inner


def count_time(func_name):
    def inner(*args, **kwargs):
        res = func_name(*args, **kwargs)
        print(f'当前功能已运行时间{time.time() - start_time}s')
        return res

    return inner
